package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.enums.DelFlag;
import com.ruoyi.system.domain.HuoPin;
import com.ruoyi.system.domain.HuoPinPinLei;
import com.ruoyi.system.domain.vo.ChangeGongYingShangRequest;
import com.ruoyi.system.mapper.HuoPinMapper;
import com.ruoyi.system.service.IHuoPinService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 货品信息 服务实现类
 * </p>
 *
 * @author qubaofeng
 * @since 2025-02-09
 */
@Service
public class HuoPinServiceImpl extends ServiceImpl<HuoPinMapper, HuoPin> implements IHuoPinService {

    @Override
    public List<HuoPin> selectWithPage(HuoPin user) {
        return baseMapper.selectWithPage(user);
    }

    @Override
    public List<HuoPin> listByCangKu(HuoPin sp) {
        LambdaQueryWrapper<HuoPin> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(HuoPin::getCangKuId, sp.getCangKuId());
        wrapper.eq(HuoPin::getDelFlag, DelFlag.NOMAL.getCode());
        return baseMapper.selectList(wrapper);
    }

    @Override
    public List<HuoPin> listByPinLei(HuoPin sp) {
        LambdaQueryWrapper<HuoPin> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(HuoPin::getPinLeiId, sp.getPinLeiId());
        wrapper.eq(HuoPin::getDelFlag, DelFlag.NOMAL.getCode());
        return baseMapper.selectList(wrapper);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean changeGongYingShang(ChangeGongYingShangRequest user) {
        for(Long huoPinId : user.getIds()) {
            HuoPin huoPin = new HuoPin();
            huoPin.setId(huoPinId);
            huoPin.setGongYingShangId(user.getNewGYSId());
            baseMapper.updateById(huoPin);
        }
        return true;
    }


}
